package com.redpigmall.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.redpigmall.api.tools.CommUtil;
import com.redpigmall.domain.OrderForm;
import com.redpigmall.logic.service.RedPigHandleOrderFormService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 */
@RestController
public class RedPigOrderFormController {
    @Autowired
    private RedPigHandleOrderFormService HandleOrderFormService;

    /**
     *
     * String url = "http://REDPIG-CLOUD-ORDERFORM/submitOrderForm?";
     *
     * 		url = url + "requestMap="+JSON.toJSONString(requestMap) ;
     *         url = "&" + url + "store_id="+store_id;
     *         url = "&" + url + "gcs="+gcs;
     *         url = "&" + url + "delivery_time="+delivery_time;
     *         url = "&" + url + "delivery_type="+delivery_type;
     *         url = "&" + url + "delivery_id="+delivery_id;
     *         url = "&" + url + "payType="+payType;
     *         url = "&" + url + "gc_ids="+JSON.toJSONString(gc_ids);
     *         url = "&" + url + "buyerId="+buyer.getId();
     *         url = "&" + url + "addrId="+addr.getId();
     *         url = "&" + url + "webType="+"web";
     *         url = "&" + url + "coupon_ids="+JSON.toJSONString(coupon_ids);
     *         url = "&" + url + "transport_ids="+JSON.toJSONString(transport_ids);
     *         url = "&" + url + "msg_ids="+JSON.toJSONString(msg_ids);
     *
     Map<String, String[]> requestMap,
     String store_id, String gcs, String delivery_time,
     String delivery_type, String delivery_id,
     String payType, String[] gc_ids,
     Long buyerId,Long addrId, String order_type,String[] coupon_ids,String[] transport_ids,String[] msg_ids
     * 发短信接口。
     * @param
     * @param
     * @return
     */
    @RequestMapping("/submitOrderForm")
    public String submitOrderForm(
            String requestMap1,
            String store_id, String gcs, String delivery_time,
            String delivery_type, String delivery_id,
            String payType,
            String buyerId,String addrId, String webType,String coupon_ids1,String transport_ids1,String msg_ids1) {

        Map<String,String> requestMap = (Map<String,String>)JSON.parse(requestMap1);

        String[] gc_ids = gcs.split(",");

        String[] coupon_ids = coupon_ids1.split(",");
        String[] transport_ids = transport_ids1.split(",");
        String[] msg_ids = msg_ids1.split(",");

        OrderForm main_order = this.HandleOrderFormService.submitOrderForm(
                requestMap, store_id, gcs, delivery_time, delivery_type,
                delivery_id, payType, gc_ids, CommUtil.null2Long(buyerId), CommUtil.null2Long(addrId), webType,coupon_ids,transport_ids,msg_ids);

        return main_order.getId().toString();
    }

    @RequestMapping("/payByBalance")
    public String payByBalance(String orderId, String webPath, String pay_msg) {
        boolean ret = this.HandleOrderFormService.payByBalance(CommUtil.null2Long(orderId),webPath, pay_msg);

        if(ret){
            return "0000";
        }

        return "0001";
    }


    @RequestMapping("/payByPayafter")
    public String payByPayafter(String orderId, String webPath, String pay_msg) {
        boolean ret = this.HandleOrderFormService.payByPayafter(CommUtil.null2Long(orderId),webPath, pay_msg);

        if(ret){
            return "0000";
        }

        return "0001";
    }


}



